//
//  RuleViewController.m
//  YunGui
//
//  Created by Hanen 3G 01 on 16/4/21.
//  Copyright © 2016年 hanen. All rights reserved.
//

#import "RuleViewController.h"
#import "PopTipView.h"
#import "QBImagePickerController.h"
#import "ShowPhotoViewController.h"
#import "CameraViewController.h"
#import "NetModel.h"
@interface RuleViewController ()<PopTipViewDelegate,QBImagePickerControllerDelegate>
{
    UILabel *numberlabel;
    UILabel *nameLabel;
    UILabel *ruleLabel;
        CGFloat   space;
    
    CGFloat lastY;
    CGFloat lastX;
    UIScrollView *_scrollView;
    
    UIButton *btn;
      NSMutableArray  *_choosePicDataArray;
    NSMutableArray  *_imagarr2;
     PopTipView *popChooseCamera;
    
    
    NSDictionary  *_dataDict;
    
    int  lastNumRule;
}
@end

@implementation RuleViewController

- (void)viewDidLoad {
     [super viewDidLoad];
    self.view.backgroundColor = GrayBackColor;
    self.navigationItem.leftBarButtonItem = [ViewTool getBackBarButtonItemWithTarget:self WithAction:@selector(backController)];
//    self.navigationController.navigationBar.backgroundColor = GrayBackColor;
//    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithTitle:@"提交" style:UIBarButtonItemStylePlain target:self action:@selector(back)];
    self.navigationItem.title = @"检查标准";
   
     space = [UIView getWidth:10.0f];
    _imagarr2 = [NSMutableArray array];
        [self addsubViews];
    
   
    if(self.inCameraChoose){
        self.navigationController.navigationBarHidden = YES;
        
        UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 ,kScreenWidth, 64)];
        navView.backgroundColor = BlueColor;
        
        [self.view addSubview:navView];
        
        UIButton *btnb = [[UIButton alloc] initWithFrame:CGRectMake( 24 , space + 24.0f, 20.0f, 20.0f)];
//        btnb .backgroundColor = BlueColor;
        [btn setBackgroundImage:[UIImage imageNamed:@"back"] forState:UIControlStateNormal];
        [btnb addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
        [navView addSubview:btnb];
    }
    
    

}
- (void)viewWillAppear:(BOOL)animated
{
//    self.navigationController.navigationBar.hidden = NO;

    [self loadCheckRuleData];
    self.navigationController.navigationBarHidden = NO;
}
- (void)loadCheckRuleData
{

    if (_BackDict) {//非第一次请求
//        _dataDict = _BackDict;
        NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.branchCheck.check.standard",@"check_id":_BackDict[@"baseInfo"][@"check_id"],@"type": _BackDict[@"next_type"]}];
        
        NSDictionary *paramersDict = [DataTool addSignToDic:dict];
        [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
            
            id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
            NSLog(@"返回下一个标准 数据%@",backData);
            _dataDict = backData[@"data"];
            btn.enabled = YES;
         
            self.ruleType = _dataDict[@"type"];
            [self refreshRuleImagetitle];
            [self useData];
        } fail:^(NSError *error) {
            NSLog(@"%@",error.localizedDescription);
        }];
    }else{//第一次 请求
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.branchCheck.check.standard",@"check_id":self.check_id,@"type": self.ruleType}];

    NSDictionary *paramersDict = [DataTool addSignToDic:dict];
    [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
 
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
               NSLog(@"评定标准 数据%@",backData);
//         [self addsubViews];
        _dataDict = backData[@"data"];
        btn.enabled = YES;
        
         [self refreshRuleImagetitle];
        [self useData];
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
   }
}
- (void)useData
{
//    numberlabel.text = _dataDict[@"base"][@"branch_no"];
//    nameLabel.text = _dataDict[@"base"][@"branch_name"];
    
    NSString *str;
   if ([self.ruleType intValue] == 1){
        str = [NSString stringWithFormat:@"地坪评价标准(最少拍摄%d张照片)",[_dataDict[@"page_min"] intValue]];
    }else if([self.ruleType intValue] == 2){
        str = [NSString stringWithFormat:@"柜体评价标准(最少拍摄%d张照片)",[_dataDict[@"page_min"] intValue]];//照片 可以有前面的数据 根据类型 获取pageMin值
    }else{
        str =  [NSString stringWithFormat:@"雨棚评价标准(最少拍摄%d张照片)",[_dataDict[@"page_min"] intValue]];
    }
    ruleLabel.text = str;
    
    
}
- (void)addBotom
{
    UIView *iv = [[UIView alloc] initWithFrame:CGRectMake(0, kScreenHeight - [UIView getHeight:66.0f] - 64.0f, kScreenWidth, [UIView getHeight:70.0f])];
    iv.backgroundColor = [UIColor whiteColor];
     [self.view addSubview:iv];
    
    UIView *lien = [ViewTool getLineViewWith:CGRectMake(0, 0, kScreenWidth , 1) withBackgroudColor:GRAYLINECOLOR];
    [iv addSubview:lien];
    
    btn = [[UIButton alloc] initWithFrame:CGRectMake([UIView getWidth:15], [UIView getHeight:13.0f], kScreenWidth - 2 * [UIView getWidth:15], iv.height - 2 * [UIView getHeight:13.0f])];
    btn.center = CGPointMake(self.view.width / 2.0f, iv.height / 2.0f);
    [btn setTitle:@"开始拍摄" forState:UIControlStateNormal];
    [btn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    btn.titleLabel.font =[UIFont systemFontOfSize:18.0f];
    btn.backgroundColor = BlueColor;
    [iv addSubview:btn];
    btn.enabled = NO;
    [btn addTarget:self action:@selector(clickCheck22) forControlEvents:UIControlEventTouchUpInside];
    iv.userInteractionEnabled = YES;
    
   
    
}
- (void)addsubViews
{
    if (_scrollView) {
        [_scrollView removeFromSuperview];
    }
//    UIView *navView = [[UIView alloc] initWithFrame:CGRectMake(0, 0 ,kScreenWidth, 64)];
//    navView.backgroundColor = GrayBackColor;
//    
//    [self.view addSubview:navView];
//    
//    UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake( space , space + 24.0f, 20.0f, 20.0f)];
//    btn .backgroundColor = BlueColor;
//   [btn addTarget:self action:@selector(clickBack) forControlEvents:UIControlEventTouchUpInside];
//    [navView addSubview:btn];
    
    CGFloat y ;
    if (self.inCameraChoose) {
        y = 64.0f;
    }else{
        y = 0.0f;
    }
    _scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, y, kScreenWidth, kScreenHeight  - y - [UIView getHeight:70])];
    _scrollView.backgroundColor  = [UIColor whiteColor];
    [self.view addSubview:_scrollView];
    
    UILabel *label1 = [ViewTool getLabelWith:CGRectMake(30.0f,  space , 70.0f, 20.0f) WithTitle:@"网点编号" WithFontSize:15.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_scrollView addSubview:label1];
    
    NSLog(@"%@",self.branch_no);
    numberlabel = [ViewTool getLabelWith:CGRectMake(label1.maxX + space,  label1.y , kScreenWidth - label1.maxX - space, 20.0f) WithTitle:self.branch_no WithFontSize:16.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
//    numberlabel.backgroundColor = BlueColor;
    [_scrollView addSubview:numberlabel];
    
    UILabel *label2 = [ViewTool getLabelWith:CGRectMake(label1.x,  label1.maxY + space , 70.0f, 20.0f) WithTitle:@"网点名称" WithFontSize:15.0f WithTitleColor:SUBTITLECOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_scrollView addSubview:label2];
    
    nameLabel = [ViewTool getLabelWith:CGRectMake(label2.maxX + space, label2.y, kScreenWidth - label2.maxX - space, 20.0f) WithTitle:self.branach_name WithFontSize:16.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_scrollView addSubview:nameLabel];
    

    UIView *lien = [ViewTool getLineViewWith:CGRectMake(label2.x, nameLabel.maxY + space, kScreenWidth - label2.x, 1) withBackgroudColor:GRAYLINECOLOR];
    [_scrollView addSubview:lien];
    
    
    ruleLabel = [ViewTool getLabelWith:CGRectMake(label2.x, lien.maxY + space , kScreenWidth - label2.x, 20.0f) WithTitle:@"  " WithFontSize:18.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
    [_scrollView addSubview:ruleLabel];
    
    CGFloat sectionH = [UIView getHeight:280.0f];
    CGFloat iamgeW = self.view.width - 10 * space;
    CGFloat imageH = [UIView getHeight:200.0f];
    
    NSArray * titleArra1 = @[@"一、2张地坪厚度：地坪左右各一张厚度照片。",@"二、2张地坪宽度照片：地坪左右各一张宽度照片。"];
    NSArray * titleArra2 = @[@"一 1张所有柜体打开1/6/10/11/16/20号柜门的全景照片",@"二、多张柜体正、反面三代柜中间加强板组焊件照片。",@"三、1张柜体左加固件。图片要求至少能够显示左侧三个加固件。",@"四、1张柜体右加固件。图片要求至少能够显示右侧三个加固件。",@"五、1张柜内左加强构件。图片能够看清左边柜内L形加固件"];
    NSArray * titleArra3 = @[@"(1).雨棚和雨棚M8连接螺栓是否安装牢固。",@"(2).检查雨棚侧边是否安装堵头。"];
    
    NSArray * imageArra1 = @[@"dp_1.jpg",@"dp_3.jpg"];//地坪
    NSArray * imageArra2 = @[@"guiti_1_1.jpg",@"guiti_2.png",@"guiti_3.jpg",@"guiti_5.jpg",@"guiti_6.jpg"];
    NSArray * imageArra3 = @[@"yupeng_1.jpg",@"yupeng_3.jpg"];
    
    NSArray * arr = [NSArray array];
    NSArray *imageArr = [NSArray array];
    //ruleTypr == 1 地坪 2 柜体 雨棚
    if([_dataDict[@"type"] intValue] == 1){
//        arr = titleArra2;
//        imageArr = imageArra2;
        arr = titleArra1;
        imageArr = imageArra1;
    }else if ([_dataDict[@"type"] intValue] == 2){
//        arr = titleArra1;
//        imageArr = imageArra1;
        arr = titleArra2;
        imageArr = imageArra2;
    }else if([_dataDict[@"type"] intValue] == 0){
        arr = titleArra3;
        imageArr = imageArra3;
    }
    CGFloat labelH = 40.0f;
    CGFloat labelW = kScreenWidth - lien.x;
    lastNumRule = arr.count;
    //先排布 前面四个
    for (int i = 0; i<arr.count ; i++) {
        UILabel *label = [ViewTool getLabelWith:CGRectMake(lien.x, ruleLabel.maxY + space +(sectionH) * i, labelW, labelH) WithTitle:arr[i] WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];
        label.tag = 85258 + i;
        label.numberOfLines = 0;
        //        label.backgroundColor = BlueColor;
        [_scrollView addSubview:label];
        
        UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake( 5 * space, label.maxY , iamgeW, imageH)];
        iamgeView.tag = 456654+ i;
        iamgeView.backgroundColor = GrayBackColor;
//        UIImage *image = [UIImage imageWithContentsOfFile:imageArr[i]];
        iamgeView.image = [UIImage imageNamed:imageArr[i]];
        [_scrollView addSubview:iamgeView];
        
        if (i == arr.count - 1) {//到时候 设定数组最后一个
            lastX = iamgeView.maxY;
        }

        }


    
//    CGFloat imageViewW = 50.0f;
//    
//    
//    for (int i = 0; i< 7; i++) {
//        CGFloat row = i / 3;
//        CGFloat col = i % 3;
//        UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(label.maxX +space + (imageViewW + space) *col, label.y + (space + imageViewW) * row, imageViewW, imageViewW)];
//        imageView.backgroundColor = [UIColor redColor];
//        [_scrollView addSubview:imageView];
//    }
    if (self.inCameraChoose) {
        _scrollView.contentSize = CGSizeMake(kScreenWidth,lastX +space );

    }else{
    _scrollView.contentSize = CGSizeMake(kScreenWidth,lastX +space + [UIView getHeight:70.0f]);
          [self addBotom];
    }
        //    UIView *imageView = [[UIView alloc] initWithFrame:CGRectMake(label.maxX +space, label.y, kScreenWidth - (label.maxX +space), 100)];
//    imageView.backgroundColor = [UIColor redColor];
//    [self.view addSubview:imageView];
    
//    if (!self.inCameraChoose) {
//      
//    }
}

- (void)refreshRuleImagetitle
{
    NSArray * titleArra1 = @[@"一、2张地坪厚度：地坪左右各一张厚度照片。",@"二、2张地坪宽度照片：地坪左右各一张宽度照片。"];
    NSArray * titleArra2 = @[@"一 1张所有柜体打开1/6/10/11/16/20号柜门的全景照片",@"二、多张柜体正、反面三代柜中间加强板组焊件照片。",@"三、1张柜体左加固件。图片要求至少能够显示左侧三个加固件。",@"四、1张柜体右加固件。图片要求至少能够显示右侧三个加固件。",@"五、1张柜内左加强构件。图片能够看清左边柜内L形加固件"];
    NSArray * titleArra3 = @[@"(1).雨棚和雨棚M8连接螺栓是否安装牢固。",@"(2).检查雨棚侧边是否安装堵头。"];
    
    NSArray * imageArra1 = @[@"dp_1.jpg",@"dp_3.jpg"];//地坪
    NSArray * imageArra2 = @[@"guiti_1_1.jpg",@"guiti_2.png",@"guiti_3.jpg",@"guiti_5.jpg",@"guiti_6.jpg"];
    NSArray * imageArra3 = @[@"yupeng_1.jpg",@"yupeng_3.jpg"];
    
    NSArray * arr = [NSArray array];
    NSArray *imageArr = [NSArray array];
    //ruleTypr == 1 地坪 2 柜体 雨棚
    if([_dataDict[@"type"] intValue] == 1){
        //        arr = titleArra2;
        //        imageArr = imageArra2;
        arr = titleArra1;
        imageArr = imageArra1;
    }else if ([_dataDict[@"type"] intValue] == 2){
        //        arr = titleArra1;
        //        imageArr = imageArra1;
        arr = titleArra2;
        imageArr = imageArra2;
    }else if([_dataDict[@"type"] intValue] == 0){
        arr = titleArra3;
        imageArr = imageArra3;
    }
    for (int i = 0; i< lastNumRule ; i++) {
        UILabel *label = [_scrollView viewWithTag:85258 + i];
        [label removeFromSuperview];
    
        
        UIImageView *iamgeView = [_scrollView viewWithTag:456654 + i];
        [iamgeView removeFromSuperview];
    }
    
    CGFloat sectionH = [UIView getHeight:280.0f];
    CGFloat iamgeW = self.view.width - 10 * space;
    CGFloat imageH = [UIView getHeight:200.0f];
    CGFloat labelH = 40.0f;
    CGFloat labelW = kScreenWidth - 30.0f;//100 是线条.x;
    for (int i = 0; i< arr.count; i++) {
        UILabel *label = [ViewTool getLabelWith:CGRectMake( 30.0f, ruleLabel.maxY + space +(sectionH) * i, labelW, labelH) WithTitle:arr[i] WithFontSize:14.0f WithTitleColor:BLACKCOLOR WithTextAlignment:NSTextAlignmentLeft];//30.0f是和横线对齐的
        label.tag = 85258 + i;
        label.numberOfLines = 0;
        //        label.backgroundColor = BlueColor;
        [_scrollView addSubview:label];
        
        UIImageView *iamgeView = [[UIImageView alloc] initWithFrame:CGRectMake( 5 * space, label.maxY , iamgeW, imageH)];
        iamgeView.tag = 456654+ i;
        iamgeView.backgroundColor = GrayBackColor;
        //        UIImage *image = [UIImage imageWithContentsOfFile:imageArr[i]];
        iamgeView.image = [UIImage imageNamed:imageArr[i]];
        [_scrollView addSubview:iamgeView];
        
        if (i == arr.count - 1) {//到时候 设定数组最后一个
            lastX = iamgeView.maxY;
        }
       
    }

    if (self.inCameraChoose) {
        _scrollView.contentSize = CGSizeMake(kScreenWidth,lastX +space );
        
    }else{
        _scrollView.contentSize = CGSizeMake(kScreenWidth,lastX +space + [UIView getHeight:70.0f]);
    }
    lastNumRule = (int)arr.count;
}
#pragma mark --开始拍摄
- (void)clickCheck22
{
    _choosePicDataArray = [NSMutableArray array];
    _imagarr2 = [NSMutableArray array];
//    NSNumber *detailId ;
//    if (self.BackDict) {
//        detailId = _dataDict
//    }
#warning 获取网上的数据 要有的话 直接进入展示图片页面
    NSMutableDictionary *dict = [NSMutableDictionary dictionaryWithDictionary:@{@"method":@"app.branchCheck.photo",@"detail_id": _dataDict[@"detail_id"]}];//需要网点检查ID
    //            [talkingArray removeAllObjects];
    NSDictionary *paramersDict = [DataTool addSignToDic:dict];
    [DataTool postWithUrl:HEAD_URL parameters:paramersDict success:^(id data) {
        id backData = [NSJSONSerialization JSONObjectWithData:data options:NSJSONReadingAllowFragments | NSJSONReadingMutableContainers error:nil];
//        NSDictionary *dict = backData[@"baseInfo"];
        NSLog(@"图片详情的%@",backData);
        
        [SVProgressHUD dismiss];
        //            CabinetCheckDetailController *cabeVC = [[CabinetCheckDetailController alloc] init];
        //            [self.navigationController popToViewController:cabeVC animated:YES];
        NSArray *iamgeArr = backData[@"data"][@"imgData"];
        if ([iamgeArr count] != 0) {
            ShowPhotoViewController *show = [[ShowPhotoViewController alloc] init];
            for (int i = 0; i< [iamgeArr count]; i++) {
                ImageModel *model = [[ImageModel alloc] init];
                model.imageId = iamgeArr[i][@"id"];
                model.url = iamgeArr[i][@"url"];
                model.file_name = iamgeArr[i][@"file_name"];
                model.file_type = iamgeArr[i][@"file_type"];
                model.created_at = iamgeArr[i][@"created_at"];
                model.detail_id = iamgeArr[i][@"detail_id"];
                [_choosePicDataArray addObject:model];
                [_imagarr2 addObject:model];
            }
           
//            model.imageId = [backData[@"data"][@"imgData"]
            show.imageArr = _choosePicDataArray;
            show.iamgeSmallArr = _imagarr2;
            show.chooseType  = 2;
            //            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:show];
            show.checkType = self.ruleType;
            show.branchId = _dataDict[@"branch_id"];
            //            [self presentViewController:nav animated:NO completion:nil];
            show.upLoadNumber = [_dataDict[@"page_min"] intValue];
            show.checkID = _dataDict[@"check_id"];
            show.checkDetailId = _dataDict[@"detail_id"];
#warning 更换切换方式
            [self.navigationController pushViewController:show animated:NO];
        }else{
        [self popvIew];
        }
    } fail:^(NSError *error) {
        NSLog(@"%@",error.localizedDescription);
    }];
    
  
}
- (void)popvIew
{
    popChooseCamera = [[PopTipView alloc] initWithFrame:CGRectMake(0, 0, [UIView getWidth:220.0f], [UIView getHeight:120.0f])];
    //    popChooseCamera.center = CGPointMake(kScreenWidth / 2.0f, kScreenHeight / 2.0f - 64);
    
    popChooseCamera.tipsLabel.text = @"请选择添加照片";
    popChooseCamera.leftTitle = @"拍照";
    popChooseCamera.righTitle = @"手机相册";
    popChooseCamera.delegate = self;
    [popChooseCamera showToView:self.view];
}
- (void)clickBack{
    [self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark --点击确定或删除
- (void)clickLeftbtnWith:(PopTipView *)popView{
    [popChooseCamera dimiss];
    if(![Tools isAllowTakePhoto]){
        [Tools showMessage:@"APP无相机访问权限，请先设置!" view:self];
        return;
    }
    CameraViewController *cameraVC = [[CameraViewController alloc] init];
    //        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:cameraVC];
    cameraVC.checkType = _dataDict[@"type"] ; // 0 ,1 ,2
//    [self presentViewController:cameraVC animated:YES completion:nil];
    cameraVC.checkId = _dataDict[@"check_id"];
    cameraVC.branchId = _dataDict[@"branch_id"];
    cameraVC.chooset = 2;
    cameraVC.detailID = _dataDict[@"detail_id"];
    cameraVC.uploadNum = [_dataDict[@"page_min"] intValue];
    cameraVC.isPush = YES;
    cameraVC.isShouldBack = NO;
    [self.navigationController pushViewController:cameraVC animated:NO];
}
- (void)clickRightbtnWith:(PopTipView *)popView{
    [popChooseCamera dimiss];
    [self takePictureInPhone1];

}
- (void)takePictureInPhone1
{
    if(![Tools isAllowPhoto]){
        [Tools showMessage:@"APP无相册访问权限，请先设置!" view:self];
        return;
    }
    if (![QBImagePickerController isAccessible]) {
        [Tools showMessage:@"相机不可用哦" view:self];
    }
    QBImagePickerController *imagePickerController = [[QBImagePickerController alloc] init];
    imagePickerController.delegate = self;
    imagePickerController.allowsMultipleSelection = YES;
    imagePickerController.maximumNumberOfSelection = 20;//最大上传5张
    
    UINavigationController *navigationController = [[UINavigationController alloc] initWithRootViewController:imagePickerController];
    [self presentViewController:navigationController animated:YES completion:NULL];
}
#pragma mark -- QBImage代理
- (void)imagePickerController:(QBImagePickerController *)imagePickerController didSelectAssets:(NSArray *)assets
{
    UIImage *image;
    NSData *data;
    NSData *data1;
//     UIImage *image2;
    for(int i = 0 ;i< assets.count; i ++){
        ALAssetRepresentation *resentation = [assets[i]  defaultRepresentation];
     image = [UIImage imageWithCGImage:[resentation fullScreenImage]];
        
//      data = UIImageJPEGRepresentation(image, 0.35);
        
//      data1 = UIImageJPEGRepresentation(image, 0.2);
//      image2 = [UIImage imageWithData:data1];
        data1 = [self imageWithImage:image scaledToSize:CGSizeMake((kScreenWidth - 5.0f * 3) / 4.0f, (kScreenWidth - 5 * 3) / 4.0f) withScale:0.1];
        data = [self imageWithImage:image scaledToSize:CGSizeMake(kScreenWidth  - 9 * space, (kScreenWidth  - 9 * space) * 1000 / 800 ) withScale:0.5];
        [_imagarr2 addObject:data1];
        
        [_choosePicDataArray addObject:data];
        
    }
    if (self.presentedViewController) {
        [self dismissViewControllerAnimated:NO completion:^{
            ShowPhotoViewController *show = [[ShowPhotoViewController alloc] init];
            show.imageArr = _choosePicDataArray;
//            show.iamgeSmallArr = nil;
            show.iamgeSmallArr = _imagarr2;
            show.chooseType  = 2;
//            UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:show];
            show.checkType = _dataDict[@"type"];
            
            show.branchId = _dataDict[@"branch_id"];
            show.checkID = self.check_id;
            show.upLoadNumber = [_dataDict[@"page_min"] intValue];
            show.checkID = _dataDict[@"check_id"];
            show.checkDetailId = _dataDict[@"detail_id"];
//            [self presentViewController:nav animated:NO completion:nil];
#warning 更换切换方式
               [self.navigationController pushViewController:show animated:NO];
        }];
    }
    //    NSLog(@"选择照片的数组个数%d",_choosePicDataArray.count);
//    [self dismissImagePickerController];
    
    //    NSLog(@"选择照片的数组个数 ===%ld",_choosePicDataArray.count);
    
  
    //    picVew.images = _choosePicDataArray;
   
    
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [picker dismissViewControllerAnimated:YES completion:nil];
}
- (void)dismissImagePickerController
{
    if (self.presentedViewController) {
        [self dismissViewControllerAnimated:YES completion:NULL];
    }
}

- (void)imagePickerControllerDidCancel1:(QBImagePickerController *)imagePickerController
{
    //    NSLog(@"*** imagePickerControllerDidCancel:");
    
    [self dismissImagePickerController];
}

- (NSData *)imageWithImage:(UIImage*)image
              scaledToSize:(CGSize)newSize withScale:(CGFloat)scale;
{
    UIGraphicsBeginImageContext(newSize);
    [image drawInRect:CGRectMake(0,0,newSize.width,newSize.height)];
    UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return UIImageJPEGRepresentation(newImage, scale);
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 6.0) {
        //需要注意的是self.isViewLoaded是必不可少的，其他方式访问视图会导致它加载，在WWDC视频也忽视这一点。
        if (self.isViewLoaded && !self.view.window)// 是否是正在使用的视图
        {
            // Add code to preserve data stored in the views that might be
            // needed later.
            // Add code to clean up other strong references to the view in
            // the view hierarchy.
            self.view = nil;// 目的是再次进入时能够重新加载调用viewDidLoad函数。
        }
    }
    dispatch_async(
                   dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)
                   , ^{
                       NSString *cachPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) objectAtIndex:0];
                       
                       NSArray *files = [[NSFileManager defaultManager] subpathsAtPath:cachPath];
//                       NSLog(@"files :%d",[files count]);
                       for (NSString *p in files) {
                           NSError *error;
                           NSString *path = [cachPath stringByAppendingPathComponent:p];
                           if ([[NSFileManager defaultManager] fileExistsAtPath:path]) {
                               [[NSFileManager defaultManager] removeItemAtPath:path error:&error];
                           }
                       };});
    
     [[SDImageCache sharedImageCache] clearDisk];//清理磁盘
    // Dispose of any resources that can be recreated.
}
- (void)viewDidUnload
{
    [super viewDidUnload];
    _imagarr2 = nil;
}
- (void)backController
{
    if(self.inCameraChoose){
           [self.navigationController popViewControllerAnimated:YES];
    }else{
    [self.navigationController popViewControllerAnimated:YES];

    }
    
//    if (self.ispush) {
//        for (UIViewController *vo in self.navigationController.viewControllers) {
//            if ([vo isKindOfClass:[ShowPhotoViewController class]]) {
//                ShowPhotoViewController *show = (ShowPhotoViewController *)vo;
//                [self.navigationController popToViewController:show animated:NO];
//            }
//        }
//    }
}
/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
